package com.jxgyl.gateway.filter;

import lombok.extern.log4j.Log4j2;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * @program: middleplatform
 * @description: token 全局过滤器
 * @author: Wanglipeng
 * @create: 2022-01-21 14:38
 **/
@Component
@Log4j2
public class TokenFilter implements GlobalFilter, Ordered {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        /**
         * 全局过滤器获取的地址，是请求的地址
         */
        ServerHttpRequest httpRequest = exchange.getRequest();
        URI uri = httpRequest.getURI();
        log.info("TokenFilter_uri="+uri.getPath());
        log.info("cookies="+httpRequest.getCookies());
        log.info("requestParam="+httpRequest.getQueryParams());

        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
